#!/usr/bin/python
'''
print the average coverage of each contig from 
454AlignmentInfo.tsv
'''
import sys

# parameters.
in_file = sys.argv[1]

# read in file.
fin = open(in_file, "rb")
lines = fin.readlines()
fin.close()

# loop over each line.
in_contig = False
tot = 0.0
sum = 0.0
name = ""
for line in lines:
	# skip header.
	if line[0] == "P": continue
	
	# find when we are in a new contig.
	if line[0] == ">":
		# print info.
		if name != "":
			if tot != 0.0 and sum != 0.0:
				print "%s\t%i\t%f" % (name, int(tot), (sum/tot))
			else:
				print "%s\t%i\t%f" % (name, int(tot), 0.0)
			
		# reset info.
		tot = 0.0
		sum = 0.0
		name = line.strip().replace(">","").split()[0]
		continue
		
	# get info.
	tmp = line.split()
	tot += 1.0
	sum += float(tmp[4])
	
# print last one.
if tot != 0.0 and sum != 0.0:
	print "%s\t%i\t%f" % (name, int(tot), (sum/tot))
else:
	print "%s\t%i\t%f" % (name, int(tot), 0.0)
